﻿Imports System.IO
Imports System.Threading
Public Class 模仿类
    Public 模仿集 As New Dictionary(Of String, List(Of HarryNode))
    Public 加载完成 As Boolean
    Private 加载路径 As String
    Public Sub New(path As String)
        加载路径 = path
        Dim t As New Thread(AddressOf Load)
        t.Start()
    End Sub
    Private Sub Load()
        If Not Directory.Exists(加载路径) Then
            Return
        End If
        Dim directories = Directory.GetDirectories(加载路径)
        For Each d In directories
            Dim files = Directory.GetFiles(d)
            Dim setName As String = IO.Path.GetFileName(d)
            模仿集.Add(setName, New List(Of HarryNode))
            For Each f In files
                If IO.Path.GetExtension(f) = ".json" Then
                    模仿集(setName).Add(New HarryNode("root", File.ReadAllText(f)))
                End If
            Next
        Next
    End Sub
    Public Function GetSets() As List(Of String)
        Return 模仿集.Keys.ToList
    End Function
    Public Function GetPath(setName As String, rootPath As String) As Dictionary(Of String, HarryNode)
        Dim result As New Dictionary(Of String, HarryNode)
        If Not 模仿集.ContainsKey(setName) Then
            Return result
        End If
        For Each node As HarryNode In 模仿集(setName)
            If node.GetAtt(rootPath) IsNot Nothing Then
                Dim childNode As HarryNode = node.GetNode(rootPath)
                For Each childPath In childNode.GetChildPath
                    If result.ContainsKey(childPath) Then
                        result(childPath).Merge(childNode.GetNode(childPath))
                    Else
                        result.Add(childPath, childNode.GetNode(childPath))
                    End If
                Next
            End If
        Next
        Return result
    End Function
End Class
